#!/bin/bash
# Copyright (c) 2023 orchy <orchy12@proton.me>
# This file is licensed under the MIT/Expat license.
# You should have received a copy of the license with this software, if not see
# https://spdx.org/licenses/MIT.html
mkdir -p bin
gcc launch/launch.c -o bin/launch
nim c -o:bin/size launch/size.nim
text=$(./bin/launch 20 40 ./bin/size)
if [ "$text" = "20 40" ]; then
	echo "[ OK ] launch/size test"
else
	echo "[FAIL] launch/size test"
	echo $text
fi

test_case () {
	nim c -o:cas cases/$1/cas.nim
	echo | XDG_CONFIG_HOME=cases/$1/.config ./bin/launch 24 80 ./cas | ./termsim > out
	if [ "$(sha256sum out | awk '{print $1}')" = "$(sha256sum cases/$1/expected | awk '{print $1}')" ]; then
		echo "[ OK ] $1"
	else
		echo "[FAIL] $1"
		exit 1
	fi
}
nim c termsim.nim
test_case 1
test_case 2
rm out
rm cas
